﻿<UserControl x:Class="ReportingManagement.Components.Queries.QueryManagement"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="700">
    <Grid>
        <Grid.Resources>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Margin" Value="3,0,3,3" />
                <Setter Property="Padding" Value="10,3" />
            </Style>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="4*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>

        <DockPanel Margin="3" Background="LightBlue">
            <DockPanel DockPanel.Dock="Top" LastChildFill="False">
                <Label Content="Report Queries" DockPanel.Dock="Left" />
                <Button x:Name="btnRefreshQueries" DockPanel.Dock="Right" Content="Refresh" Width="Auto" Margin="3" 
                        Padding="3" Click="btnRefreshQueries_Click" FontSize="9" />
            </DockPanel>
            
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
                <Button x:Name="btnModify" Click="btnModify_Click">Modify</Button>
                <Button x:Name="btnRun" Click="btnRun_Click">Run...</Button>
                <Button x:Name="btnDelete" Click="btnDelete_Click">Delete</Button>
                <Button x:Name="btnSave" Content="Save" Click="btnSave_Click" />
            </StackPanel>
            <ListBox x:Name="lstReportQueries" Margin="3" MinHeight="250" Grid.Row="1"
                     DockPanel.Dock="Bottom" SelectionChanged="lstReportQueries_SelectionChanged"
                     HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Deleted}" Value="True">
                                <Setter Property="Background" Value="Red" />
                                <Setter Property="Foreground" Value="White" />
                            </DataTrigger>
                            <!--Query objects does not contain associated category info-->
                            <!--<DataTrigger Binding="{Binding QueryCategories.Count}" Value="0">
                                <Setter Property="Foreground" Value="Brown" />
                            </DataTrigger>-->
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Description}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DockPanel>

        <GridSplitter Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch" Width="3" Background="LightGray" ShowsPreview="True" />

        <Grid Grid.Column="2" Margin="3">
            <Grid.Resources>
                <Style TargetType="{x:Type Label}">
                    <Setter Property="Margin" Value="3,10,0,0" />
                    <Setter Property="Padding" Value="0" />
                </Style>
                <Style TargetType="{x:Type ListBox}">
                    <Setter Property="Margin" Value="3" />
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="2*"/>
            </Grid.RowDefinitions>

            <StackPanel>
                <Label Content="Assign query to category" />
                <StackPanel Orientation="Horizontal" Hyperlink.Click="Hyperlink_Click">
                    <Label>
                        <Hyperlink FontSize="10" Tag="ADD">Add Category</Hyperlink>
                    </Label>
                    <Label>
                        <Hyperlink FontSize="10" Tag="EDIT">Edit Category</Hyperlink>
                    </Label>
                    <Label>
                        <Hyperlink FontSize="10" Tag="DELETE">Delete Category</Hyperlink>
                    </Label>
                    <Label>
                        <Hyperlink FontSize="10" Tag="RUN">Run</Hyperlink>
                    </Label>
                </StackPanel>                
            </StackPanel>
            <ListBox x:Name="lstQueryCategories" Grid.Row="1" HorizontalContentAlignment="Stretch" 
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="{x:Type Label}">
                                    <Setter Property="Margin" Value="2" />
                                    <Setter Property="Padding" Value="2" />
                                </Style>
                            </Grid.Resources>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <CheckBox x:Name="cboQuery" Margin="2" />
                            <Label Grid.Column="1" FontWeight="Bold" Content="{Binding Name}" />
                            <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding Description}" 
                                       TextTrimming="CharacterEllipsis" ToolTip="{Binding Description}" Margin="2,0,2,5" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Queries.Count}" Value="0">
                                <Setter Property="Background" Value="MistyRose" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>

            <Label Grid.Row="2" Content="Queries in selected category" />
            <ListBox Grid.Row="3" Margin="3" HorizontalContentAlignment="Stretch"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     ItemsSource="{Binding ElementName=lstQueryCategories, Path=SelectedItem.Queries}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Name}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

        </Grid>

        <GridSplitter Grid.Column="3" VerticalAlignment="Stretch" Width="3" Background="LightGray" ShowsPreview="True" HorizontalAlignment="Stretch" />

        <Grid Grid.Column="4" Margin="3" DataContext="{Binding ElementName=lstReportQueries, Path=SelectedItem}">
            <Grid.Resources>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Margin" Value="3" />
                </Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="Margin" Value="3" />
                    <Setter Property="Padding" Value="1" />
                </Style>
                <Style TargetType="{x:Type ListBox}">
                    <Setter Property="Margin" Value="3" />
                </Style>
                <Style TargetType="{x:Type Label}">
                    <Setter Property="Margin" Value="3,10,0,2" />
                    <Setter Property="FontWeight" Value="Bold" />
                    <Setter Property="Padding" Value="0" />
                </Style>
            </Grid.Resources>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Label Content="Query Name" />
            <TextBox Grid.Row="1" Text="{Binding Name}" TextWrapping="Wrap" />

            <Label Grid.Row="2" Content="Query Description" />
            <TextBox Grid.Row="3" TextWrapping="Wrap" Text="{Binding Description}" />

            <Label Grid.Row="4" Content="More Information" />
            <TextBox Grid.Row="5" TextWrapping="Wrap" Text="{Binding More}" />

            <Label Grid.Row="6" Content="Internal Name" />
            <TextBox Grid.Row="7" Text="{Binding InternalName}" IsReadOnly="True" TextWrapping="Wrap" />

            <Label Grid.Row="8" Margin="0,10,0,-3" Hyperlink.Click="Hyperlink_Click">
                <Hyperlink Tag="EDIT_PARAMETERS">Query Parameters</Hyperlink>
            </Label>
            <ListBox Grid.Row="9" DisplayMemberPath="Name"
                     ItemsSource="{Binding ElementName=lstReportQueries, Path=SelectedItem.QueryParameters}" />

            <TextBlock Grid.Row="10" Text="Editorial History" Visibility="Collapsed" />
        </Grid>

    </Grid>
</UserControl>
